package com.cqie.rbac.controller;


import com.cqie.rbac.bo.DepartmentBo;
import com.cqie.rbac.entity.Department;
import com.cqie.rbac.entity.TestDepartment;
import com.cqie.rbac.mapper.TestDepartmentMapper;
import com.cqie.rbac.service.IDepartmentService;
import com.cqie.rbac.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 学院表 前端控制器
 * </p>
 *
 * @author 单机吧
 * @since 2021-10-08
 */
@Api(tags = "学院管理")
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService iDepartmentService;


    @Autowired
    private TestDepartmentMapper testDepartmentMapper;

    @ApiOperation("获取学院列表信息")
    @GetMapping("/getDepartmentTree")
    public Result GetDepartment(){
        List<Department> list = iDepartmentService.DepartmentTree();
        return Result.ok().data(list);
    }

    @ApiOperation("新增学院")
    @PostMapping("/InsertDepart")
    public Result InsertDepart(TestDepartment testDepartment){
        testDepartmentMapper.insertone(testDepartment);
        return Result.ok();
    }

    @ApiOperation("删除学院")
    @PostMapping("/DeleteDepart")
    public Result DeleteDepart(Integer id){
        testDepartmentMapper.deleteByPrimaryKey(id);
        return Result.ok();
    }

    @ApiOperation("修改学院")
    @PostMapping("/UpdateDepart")
    public Result UpdateDepart(TestDepartment testDepartment){
        testDepartmentMapper.updateByPrimaryKeySelective(testDepartment);
        return Result.ok();
    }


    @ApiOperation("根据id查询学院")
    @GetMapping("/getDepartmentNameById")
    public Result GetDepartmentNameById(Long id){
        Department department = iDepartmentService.GetDepartmentNameById(id);
        return Result.ok().data(department);
    }

    @ApiOperation("编辑或修改学院信息")
    @GetMapping("/updateOrAddMenu")
    public Result UpdateOrAddMenu(@RequestBody DepartmentBo bo){
        return iDepartmentService.UpdateOrAddMenu(bo);
    }
}
